<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/style/js/TableFreeze.js"></script>
<script src="__PUBLIC__/style/js/plugins/nice-scroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/chart/highcharts.js"></script>
<script src="__PUBLIC__/js/chart/modules/exporting.js"></script>
<script>
	$(window).resize(function() {
	    var height_frm = $(document.body).height();
	    var height_div = height_frm/2;
	    $('#container').css("height", height_div);
	});
</script>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-lg-12">
			<include file="Public:alert" />
			<div class="ibox float-e-margins">
				<include file="Public:analytics_left" />
				<input type="hidden" id="content_id" value="{$content_id}">
				<div class="col-lg-10">
					<div class="ibox-content" style="padding-bottom:10px;border-bottom: none;">
						<form id="" class="form-group" method="get" style="margin-bottom: 0px;">
							<div class="row" style="height: 45px;">
								<div class="col-lg-4">
									<div class="pull-left" >
										<span style="font-size: 18px;color: #000;">
											<?php
												switch($_GET['content_id']){
													case 1:$content_name = '合同金额统计';break;
													case 2:$content_name = '回款金额统计';break;
													default :$content_name = '合同金额TOP10';break;
												}
												echo $content_name;
											?>
										</span>
									</div>
								</div>
								<div class="col-lg-8">
								</div>
							</div>
							<div class="row" >
								<input type="hidden" name="m" value="contract" />
								<input type="hidden" name="a" value="analytics" />
								<input type="hidden" name="content_id" value="<php>echo $content_id = $_GET['content_id'] ? intval($_GET['content_id']) : 1;</php>" />
								<div class="col-lg-12" >
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<input class="form-control required Wdate" aria-required="true" type="text" name="years" onFocus="WdatePicker({dateFmt:'yyyy'})" value="{$years}" />
												<i class="glyphicon glyphicon-calendar fa fa-calendar" style="position: absolute;bottom: 10px;right: 24px;top: auto;cursor: pointer;"></i>
											</div>
										</li>
									</ul>
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="department" id="department" onchange="changeRole()">
													<option class="all" value="all">{:L('ALL')}</option>
													<volist name="departmentList" id="vo">
														<option value="{$vo.department_id}">{$vo.name}</option>
													</volist>
												</select>
											</div>
										</li>
									</ul>
									<if condition = "$_GET['content_id'] neq 3">
									<ul class="nav pull-left" style="margin:2px 0 0 15px;">
										<li>
											<div class="input-group">
												<select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="role" id="role" onchange="changeCondition()">
													<option class="all" value="all">{:L('ALL')}</option>
													<volist name="roleList" id="vo">
														<option value="{$vo.role_id}" <if condition="$_GET['role'] eq $vo['role_id']">selected</if>>{$vo.role_name}-{$vo.user_name}</option>
													</volist>
												</select>
											</div>
										</li>
									</ul>
									</if>
									<div class="pull-left" style="margin-left: 20px;">
										<button type="submit" id="analytics_search" class="btn btn-primary">{:L('SEARCH')}</button>
									</div>
								</div>
							</div>
						</form>
					</div>
					<div class="ibox-content" id="right_height" style="border-top: none;padding-top: 0px;">
						<if condition = "$_GET['content_id'] eq 1 || $_GET['content_id'] eq ''">
							<div id="content_1" class="th_content" style="position:relative;">
								<div id="container" style="max-width:inherit;max-height: 450px;margin: 0 auto">
									<include file="Public:nodata" />
								</div>
							</div>
						</if>
						<if condition = "$_GET['content_id'] eq 2">
							<div id="content_2" class="th_content" style="position:relative;">
								<div id="container" style="max-width:inherit;max-height: 450px;margin: 0 auto">
									<include file="Public:nodata" />
								</div>
							</div>
						</if>
						<if condition = "$_GET['content_id'] eq 3">
							<div id="content_3" class="th_content" style="position:relative;">
								<div id="container3" style="max-width:inherit;max-height: 450px;margin: 0 auto">
									<include file="Public:nodata" />
								</div>
							</div>
						</if>
						<div class="clearfix"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div style="display: none;" id="dialog-role-info" title="{:L('EMPLOYEE_INFORMATION')}">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#dialog-role-info").dialog({
		autoOpen: false,
		modal: true,
		width: 600,
		maxHeight: 550,
		position: ["center",100]
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
	$(function () {
		var chart; //合同金额统计
		$('#container').highcharts({
	        chart: {
	            type: 'column'
	        },
	        title: {
	            text: '{$type_name}'
	        },
	        subtitle: {
	            text: ''
	        },
	        xAxis: {
	            categories: [{$contract_month}],
	            crosshair: true
	        },
	        yAxis: {
	            min: 0,
	            title: {
	                text: '元'
	            }
	        },
	        tooltip: {
	            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
	            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
	            '<td style="padding:0"><b>{point.y:.1f} 元</b></td></tr>',
	            footerFormat: '</table>',
	            shared: true,
	            useHTML: true
	        },
	        plotOptions: {
	            column: {
	                pointPadding: 0.2,
	                borderWidth: 0
	                // colorByPoint:true
	            }
	        },
	        series: [{$analytics_data}]
	    });

	    $('#container3').highcharts({
	        chart: {
	            type: 'bar'
	        },
	        title: {
	            text: '员工合同金额TOP10排行榜'
	        },
	        subtitle: {
	            text: ''
	        },
	        xAxis: {
	            categories: [{$user_arr}],
	            title: {
	                text: null
	            }
	        },
	        yAxis: {
	            min: 0,
	            title: {
	                text: '合同金额 (元)',
	                align: 'high'
	            },
	            labels: {
	                overflow: 'justify'
	            }
	        },
	        tooltip: {
	            valueSuffix: ' 元'
	        },
	        plotOptions: {
	            bar: {
	                dataLabels: {
	                    enabled: true,
	                    allowOverlap: true
	                }
	            }
	        },
	        legend: {
	            layout: 'vertical',
	            align: 'right',
	            verticalAlign: 'top',
	            x: -40,
	            y: 100,
	            floating: true,
	            borderWidth: 1,
	            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
	            shadow: true
	        },
	        credits: {
	            enabled: false
	        },
	        series: [{
	            name: '合同金额',
	            data: [{$price_arr}]
	        }]
	    });
	});

	function changeRole(){
		department_id = $("#department option:selected").val();
		$.ajax({
			type:'get',
			url:'index.php?m=user&a=getrolebydepartment&department_id='+department_id,
			async:true,
			success:function(data){
				options = '<option value="all">{:L('ALL')}</option>';
				if(data.data != null){
					$.each(data.data, function(k, v){
						options += '<option value="'+v.role_id+'">'+v.role_name+"-"+v.user_name+'</option>';
					});
				}
				$("#role").html(options);
				<if condition="$_GET['role']">
					$("#role option[value='{$Think.get.role}']").prop("selected", true);
				</if>
			},
			dataType:'json'
		});
	}

	$("#user_type").click(function(){
		var user_type = $(this).is(':checked');
		var date = $('#reservation').val();
		if(user_type == true){
			window.location.href = "{:U('contract/analytics','content_id=1'.'&date=')}"+date;
		}else{
			window.location.href = "{:U('contract/analytics','&content_id=1'.'&date=')}"+date+'&user_type=1';
		}
	});

	<if condition="$_GET['department'] and $_GET['department'] neq 'all'">
		$("#department option[value='{$Think.get.department}']").prop("selected", true);
		changeRole();
	</if>
	<if condition="$_GET['department'] eq 'all'">
		$("#role option[value='{$Think.get.role}']").prop("selected", true);
	</if>
</script>
<include file="Public:footer" />
